package org.monster.context.core.parameter;

import org.monster.context.core.headerfilter.HeaderFilterChain;
import org.monster.context.core.request.HttpRequest;

import javax.servlet.FilterChain;

/**
 * 参数Get
 *
 * @author Monster
 */
public class ParameterGet extends Parameter {

    /**
     * 获取 头参数
     *
     * @param request  请求
     * @param response 响应
     * @param chain    通道
     */
    @Override
    public void getHeadParameter(HttpRequest request, HttpResponse response,
                                 HeaderFilterChain chain) {
        String requestURI = request.getRequestURI();
        if (requestURI != null) {
            int index = requestURI.indexOf('?');
            if (index != -1) {
                String params = requestURI.substring(index + 1,
                        requestURI.length());
                String[] paramArray = params.split("&&");
                getParams(request, paramArray);
            }
        }
    }

    /**
     * 获取 头参数
     *
     * @param request  请求
     * @param response 响应
     * @param chain    通道
     */
    @Override
    public void getHeadParameter(HttpRequest request, HttpResponse response,
                                 FilterChain chain) {
        String requestURI = request.getRequestURI();
        if (requestURI != null) {
            int index = requestURI.indexOf('?');
            if (index != -1) {
                String params = requestURI.substring(index + 1,
                        requestURI.length());
                String[] paramArray = params.split("&&");
                getParams(request, paramArray);
            }
        }
    }
}
